package Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/*public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int arrNum = input.nextInt();
        int[] arr = new int[arrNum];
        for (int i = 0; i < arrNum; i++) {
            arr[i] = input.nextInt();
        }
    }

    public static int function(int[] arr) {
        return 1;
    }
}*/

/*
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();
        System.out.println(findMax(str, str.length()));
    }

    private static int findMax(String str, int n) {
        char[] chars = str.toCharArray();

        if (str == null || n < 4) {
            return -1;
        }
        int count = 0;
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= n; j++) {
                for (int k = 0; k <= n; k++) {
                    if ((i + j + k) == 4 && (3 * i + 2 * j + k) == n) {
                        count += 1;
                    }
                }
            }
        }
        return count;
    }
}
*/

/*
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int N = input.nextInt();
        int[] arr = new int[N];
        for (int i = 0; i < N; i++) {
            arr[i] = input.nextInt();
        }
        int res = 0;
        if (idLegal(arr)) {
            res = 1;
        }
        System.out.println(res);
    }

    public static boolean idLegal(int[] data) {
        int count = 0;
        for (int num : data
                ) {
            if (count == 0) {
                if ((num & 0x80) == 0) {
                    count = 0;
                } else if ((num & 0xe0) == 0xc0) {
                    count = 1;
                } else if ((num & 0xf0) == 0xe0) {
                    count = 2;
                } else if ((num & 0xf8) == 0xf0) {
                    count = 3;
                } else {
                    return false;
                }
            } else {
                if ((num & 0xc0) != 0x80) {
                    return false;
                }
                count--;
            }
        }
        if (count == 0) {
            return true;
        } else {
            return false;
        }

    }

}
*/
/*
public class Main {
    public static int max = 0;

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int m = input.nextInt();
        ArrayList<Integer>[] list = new ArrayList[n + 1];
        for (int i = 1; i <= n; i++) {
            list[i] = new ArrayList<>();
        }
        for (int i = 0; i < m; i++) {
            int a = input.nextInt();
            int b = input.nextInt();
            list[b].add(a);
        }
        int count = 0;
        for (int i = 1; i <= n; i++) {
            int temp = 1;
            int[] arr = new int[n + 1];
            arr[i] = 1;
            temp += function(list, arr, i);
            if (temp == n) {
                count++;
            }
        }
        System.out.println(count + "");
    }

    public static int function(ArrayList<Integer>[] lists, int[] arr, int i) {
        int max = 0;
        for (int j = 0; j < lists[i].size(); j++) {
            if (arr[lists[i].get(j)] == 0) {
                max++;
                arr[lists[i].get(j)] = 1;
                max += function(lists, arr, lists[i].get(j));
            }
        }
        return max;
    }
}
*/
public class Main07 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int M = input.nextInt();
        int[][] arr = new int[M][M];
        for (int i = 0; i < M; i++) {
            for (int j = 0; j < M; j++) {
                arr[i][j] = input.nextInt();
            }
        }
        int num = function1(arr);
        System.out.println(num);
    }

    private static int function1(int[][] arr) {
        int deptNum = 0;
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                if (arr[i][j] == 1) {
                    int teamNum = function2(arr, i, j, 0);
                    deptNum = teamNum == 0 ? deptNum : deptNum + 1;
                }
            }
        }
        return deptNum;
    }

    private static int function2(int[][] arr, int i, int j, int num) {
        if (arr[i][j] != 1) {
            return num;
        }
        arr[i][j] = -1;
        num += 1;
        if (i - 1 > -1) {
            num = function2(arr, i - 1, j, num);
        }
        if (j + 1 < arr[i].length) {
            num = function2(arr, i, j + 1, num);
        }
        if (i + 1 < arr.length) {
            num = function2(arr, i + 1, j, num);
        }
        if (j - 1 > -1) {
            num = function2(arr, i, j - 1, num);
        }
        return num;
    }

}